package com.payment.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.payment.common.base.AjaxResult;
import com.payment.common.page.TableDataInfo;
import com.payment.common.utils.ExcelUtil;
import com.payment.framework.web.base.BaseController;
import com.payment.system.domain.IssBank;
import com.payment.system.domain.MerchantIncreaseLimit;
import com.payment.system.service.IIssBankService;
import com.payment.system.service.IMerchantImageService;
import com.payment.system.service.IMerchantIncreaseLimitService;

/**
 * 商户信用卡 信息操作处理
 * 
 * @author payment
 * @date 2018-12-31
 */
@Controller
@RequestMapping("/system/merchantIncreaseLimit")
public class MerchantIncreaseLimitController extends BaseController
{
    private String prefix = "system/merchantIncreaseLimit";
	@Autowired
	private IMerchantImageService merchantImageService;
	@Autowired
	private IMerchantIncreaseLimitService merchantIncreaseLimitService;
	@Autowired
	private IIssBankService issBankService;
	
	@RequiresPermissions("system:merchantIncreaseLimit:view")
	@GetMapping()
	public String merchantIncreaseLimit()
	{
	    return prefix + "/merchantIncreaseLimit";
	}
	
	/**
	 * 查询商户信用卡列表
	 */
	@RequiresPermissions("system:merchantIncreaseLimit:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MerchantIncreaseLimit merchantIncreaseLimit)
	{
		startPage();
        List<MerchantIncreaseLimit> list = merchantIncreaseLimitService.selectMerchantIncreaseLimitList(merchantIncreaseLimit);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商户信用卡列表
	 */
	@RequiresPermissions("system:merchantIncreaseLimit:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerchantIncreaseLimit merchantIncreaseLimit)
    {
    	List<MerchantIncreaseLimit> list = merchantIncreaseLimitService.selectMerchantIncreaseLimitList(merchantIncreaseLimit);
        ExcelUtil<MerchantIncreaseLimit> util = new ExcelUtil<MerchantIncreaseLimit>(MerchantIncreaseLimit.class);
        return util.exportExcel(list, "merchantIncreaseLimit");
    }
	




	/**
	 * 信用卡认证详情
	 * 根据商户id
	 */
	@GetMapping("/detail/{iD}")
	public String detail(@PathVariable("iD") String iD, ModelMap mmap)
	{
		MerchantIncreaseLimit merchantIncreaseLimit=merchantIncreaseLimitService.selectMerchantDetailById(iD);
		mmap.put("merchantIncreaseLimit", merchantIncreaseLimit);
		mmap.put("merchantImage",merchantImageService.selectMerchantImageListByMerchantId(iD));
		if(merchantIncreaseLimit!=null&&merchantIncreaseLimit.getBankName()!=null){
			IssBank issBank=issBankService.selectIssBankByCode(merchantIncreaseLimit.getBankName());
			mmap.put("bankName",issBank.getBankName());
		}else{
			mmap.put("bankName","");
		}

		return prefix + "/detail";
	}


	/**
	 * 设置CVN
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		mmap.put("merchantIncreaseLimit", merchantIncreaseLimitService.selectMerchantIncreaseLimitById(id));
		return prefix + "/edit";
	}

	/**
	 * 修改保存
	 */
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MerchantIncreaseLimit merchantIncreaseLimit)
	{

		return toAjax(merchantIncreaseLimitService.updateMerchantIncreaseLimit(merchantIncreaseLimit));
	}


	/**
	 * 删除信用卡
	 */
	@RequiresPermissions("system:merchantIncreaseLimit:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		return merchantIncreaseLimitService.deleteIncreaseLimitById(ids);
	}


}
